#include "index_reader.h"

void PrintIndexList(IndexList* indexList)
{
    fprintf(stdout, "sign[%ld]\n", indexList->idxHead->tsign);
    for(size_t i = 0; i < indexList->idxHead->num_idx; ++i)
    {
        fprintf(stdout, "id[%d], weight[%d]\n", indexList->idxIndex[i].id, indexList->idxIndex[i].weight);
        offset_t* offSet = indexList->offSet+indexList->idxCount[i].off;
        for(size_t j = 0; j < indexList->idxCount[i].num; ++j)
        {
            fprintf(stdout, "texttype[%d], offset[%d]\n", offSet[j].texttype, offSet[j].offset);
        }
    }
}

int main(int argc, char** argv)
{
    log_init();
    g_log_context.log_level = LOG_DEBUG;
    if(argc != 4)
    {
        fprintf(stderr, "usage: ./test_reader index_path term level.\n");
        return -1;
    }
    const char* index_path = argv[1];
    char* term_str = argv[2];
    int level = atoi(argv[3]);
    IndexReader indexReader;
    int ret = indexReader.Init(index_path);
    if(ret < 0)
    {
        FATAL("init index error");
        return -1;
    }
    uint64_t termSign = 0;
    ret = create_sign64(term_str, strlen(term_str), &termSign);
    if(ret < 0)
    {
        FATAL("create_sign64 is error, term[%s]", term_str);
        return -1;
    }
    NOTICE("term[%s], sign[%llu]\n", term_str, termSign);
    IndexList indexList;
    ret = indexReader.ReadIndex(termSign, &indexList, level);
    if(ret < 0)
    {
        WARNING("term is not found!");
        return -1;
    }
    PrintIndexList(&indexList);
    return 0;
}




















/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */
